import jsonp from 'common/js/jsonp'
import { commonParams, options, baseUrl } from './config'
import axios from 'axios'

export function getTopList() {
    const url = baseUrl + 'api/getTopList'
    const data = Object.assign({}, commonParams, {
        '-': 'recom2081473154824931',
        g_tk: 5381,
        hostUin: 0,
        format: 'json',
        platform: 'yqq.json',
        data: {
            toplist: {
                module: 'musicToplist.ToplistInfoServer',
                method: 'GetAll',
                param: {}
            }
        }
    })

    return axios.get(url, {
        params: data
    }).then((res) => {
        return Promise.resolve(res.data)
    })
}

export function getMusicList(topid) {
    const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg'

    const data = Object.assign({}, commonParams, {
        topid,
        page: 'detail',
        type: 'top',
        tpl: 3,
        platform: 'h5',
        needNewCode: 1
    })

    return jsonp(url, data, options)
}
